package br.com.projeto.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private static SessionFactory sessionFactory;

	private HibernateUtil() {

	}

	public static SessionFactory getSessionFactory() {

		if (sessionFactory == null) {
			try {
				Configuration ac = new AnnotationConfiguration();
				sessionFactory = ac.configure().buildSessionFactory();

			} catch (Throwable ex) {

				System.err.println("Initial SessionFactory creation failed."
						+ ex);
				throw new ExceptionInInitializerError(ex);
			}

			return sessionFactory;

		} else {
			return sessionFactory;
		}

	}

	public static void main(String[] args) {
		HibernateUtil.getSessionFactory();
	}

}
